<?php

namespace app\api\controller;

use app\admin\model\house\HouseReceiveTime;
use app\api\model\house\HouseComplement;
use app\api\model\house\HouseFacilitiesCategory;
use app\api\model\house\HouseLevel;
use app\api\model\house\HouseMediaCategory;
use app\api\model\house\HouseBedType;
use app\api\model\house\HouseFacilities;
use app\api\model\house\HouseManageCategory;
use app\api\model\house\HouseManage;
use app\api\model\house\HouseParkComplement;
use app\api\model\house\HouseType;
use app\common\controller\Api;

class Houseparam extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    //房屋类型
    public function houseType()
    {
        $house_type_model = new HouseType();
        $type_list = $house_type_model->getTypeList();
        $data = [];
        foreach ($type_list as $k=>$v){
            $data[] = [
                'title'=>$v,
                'data'=>HouseType::where(['type'=>$k])->order('weigh desc')->field('type_id,name')->select()
            ];
        }
        $this->success('',$data);
    }

    //房屋设施
    public function houseFacilities()
    {
        //$house_facilities_model = new HouseFacilities();
        //$type_list = $house_facilities_model->getTypeList();
        $type_list = HouseFacilitiesCategory::order('weigh desc')->select();
        $data = [];
        foreach ($type_list as $k=>$v){

            $list = HouseFacilities::where(['category_id'=>$v['id']])->order('weigh desc')
                ->field('facilities_id,name')->select();
            if (count($list)>0){
                $data[] = [
                    'title'=>$v['name'],
                    'data'=>$list
                ];
            }

        }
        $this->success('',$data);
    }

    //园区配套
    public function houseParkComplement()
    {
        $house_park_complement_model = new HouseParkComplement();
        $type_list = $house_park_complement_model->getTypeList();
        $data = [];
        foreach ($type_list as $k=>$v){
            $data[] = [
                'title'=>$v,
                'data'=>HouseParkComplement::where(['type'=>$k])->order('weigh desc')->field('id,name')->select()
            ];
        }
        $this->success('',$data);
    }

    //床铺类型
    public function houseBedType()
    {
        $list = HouseBedType::order('weigh desc')->column('name');
        $this->success('',$list);
    }

    //物业管理
    public function manage()
    {
        $category_list = HouseManageCategory::order('weigh desc')->field('id,name')->select();
        foreach ($category_list as $k=>$v){
            $category_list[$k]['child'] = HouseManage::where(['category_id'=>$v['id']])
                ->order('weigh desc')->field('id as manage_id,name')->select();
        }
        $this->success('',$category_list);
    }

    //照片分类
    public function mediaCategory()
    {
        $type = input('type',0);

        $category_list = HouseMediaCategory::where(['type'=>$type])->order('weigh desc')->field('id,name')->select();

        $this->success('',$category_list);
    }

    //房屋等级
    public function houseLevel()
    {
        $list = HouseLevel::order('level asc')->field('id,level,image,content')->select();
        $this->success('',$list);
    }

    //等级详情
    public function houseLevelInfo()
    {
        $id = input('id',0);
        $info = HouseLevel::get($id);
        $this->success('',$info);
    }

    //换房/共享/拼房规则
    public function rule()
    {
        $data = [
            'house_share_rule'=>\app\common\model\Config::get(['name'=>'house_share_rule'])->value,
            'house_group_rule'=>\app\common\model\Config::get(['name'=>'house_group_rule'])->value,
            'house_change_rule'=>\app\common\model\Config::get(['name'=>'house_change_rule'])->value
        ];
        $this->success('',$data);
    }

    //最多入驻天数
    public function maxLiveDay()
    {
        $data = \app\common\model\Config::get(['name'=>'max_live_day'])->value;

        $this->success('',$data);
    }

    //配套服务
    public function houseComplement()
    {

        $list = HouseComplement::order('weigh desc')->field('id,name,unit')->select();

        $this->success('',$list);
    }

    public function receiveTime()
    {
        $list = HouseReceiveTime::order('weigh desc')->select();

        $this->success('',$list);
    }

    public function uploadRule()
    {

        $value = \app\common\model\Config::get(['name'=>'house_img_upload_rule'])->value;
        $this->success('',$value);
    }

}